package cn.jcby.app.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class CostTimeAspect {

    @Pointcut("@annotation(cn.jcby.app.annotation.CostTime)")
    public void costTime(){}

    @Around("costTime()")
    public Object costTimeAround(ProceedingJoinPoint joinPoint) throws Throwable {
        Object obj = null ;
        Long beginTime = System.currentTimeMillis() ;
        obj = joinPoint.proceed() ;
        //获取识别信息
        String className = joinPoint.getSignature().getDeclaringTypeName() ;
        String methodName = joinPoint.getSignature().getName();
        //耗时
        Long useTime = System.currentTimeMillis()-beginTime ;
        log.info("类:[{}],方法：[{}] ,接口耗时：[{}ms]",className,methodName,useTime);
        return obj ;
    }
}
